package com.bum.api.core.bo;

import com.bum.api.core.bo.om.Client;
import com.bum.api.core.exp.om.Params;
import com.bum.api.core.util.request.MobileAgentChecker;

public class ClientBO {
	public void checkClientAgent(String code, String userAgent, boolean debugMode, Params params) throws Exception {
		Client client = Client.get(code);
		if (client == null) {
			throw new Exception("Invalid signature");
		}

		switch (client) {
			case OlaApk:
			case FishootApk:
				if (!MobileAgentChecker.isAndroidMobile(userAgent)) {
					throw new Exception("Invalid signature");
				}
				break;

			case OlaIphone:
			case FishootIphone:
				if (!MobileAgentChecker.isAppleMobile(userAgent)) {
					throw new Exception("Invalid signature");
				}
				break;

			case OlaWinPhone:
				// TODO detect client win phone
				break;

			case JsonFetcher:
				String version = params.getValue("apv");
				version = "JSON Fetcher: " + version;

				if (!debugMode && !version.equals(userAgent)) {
					throw new Exception("Invalid signature");
				}
				break;
			case OlaMeWeb:
				/**
				 * Chưa nghĩ ra cái gì để check thêm
				 */
				break;

			case WebTest:
				if (!debugMode) {
					params.remove("cid");
					throw new Exception("Invalid signature");
				}
				break;

			default:
		}
	}

}
